package com.cadre.common.utils.oldutil;

import java.io.*;

/* loaded from: TextUtil.class */
public class TextUtil {
    public static BufferedReader bufread;
    private static String path = "D:/suncity.txt";
    private static File filename = new File(path);
    private static String readStr = "";

    public TextUtil(String path2, File filename2) {
        path = path2;
        filename = filename2;
    }

    public static void creatTxtFile() throws IOException {
        if (!filename.exists()) {
            filename.createNewFile();
            System.err.println(filename + "已创建！");
        }
    }

    /*  JADX ERROR: JadxRuntimeException in pass: BlockProcessor
        jadx.core.utils.exceptions.JadxRuntimeException: Unreachable block: B:7:0x0043
        	at jadx.core.dex.visitors.blocks.BlockProcessor.checkForUnreachableBlocks(BlockProcessor.java:86)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.processBlocksTree(BlockProcessor.java:52)
        	at jadx.core.dex.visitors.blocks.BlockProcessor.visit(BlockProcessor.java:44)
        */
    public static String readTxtFile() {
        /*
            java.io.FileReader r0 = new java.io.FileReader     // Catch: FileNotFoundException -> 0x004b
            r1 = r0
            java.io.File r2 = com.tdqy.cadre.modular.profess.utils.TextUtil.filename     // Catch: FileNotFoundException -> 0x004b
            r1.<init>(r2)     // Catch: FileNotFoundException -> 0x004b
            r5 = r0
            java.io.BufferedReader r0 = new java.io.BufferedReader     // Catch: FileNotFoundException -> 0x004b
            r1 = r0
            r2 = r5
            r1.<init>(r2)     // Catch: FileNotFoundException -> 0x004b
            com.tdqy.cadre.modular.profess.utils.TextUtil.bufread = r0     // Catch: FileNotFoundException -> 0x004b
        L_0x0016:
            java.io.BufferedReader r0 = com.tdqy.cadre.modular.profess.utils.TextUtil.bufread     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            java.lang.String r0 = r0.readLine()     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            r1 = r0
            r4 = r1
            if (r0 == 0) goto L_0x0040
            java.lang.StringBuilder r0 = new java.lang.StringBuilder     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            r1 = r0
            r1.<init>()     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            java.lang.String r1 = com.tdqy.cadre.modular.profess.utils.TextUtil.readStr     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            java.lang.StringBuilder r0 = r0.append(r1)     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            r1 = r4
            java.lang.StringBuilder r0 = r0.append(r1)     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            java.lang.String r1 = "\r\n"
            java.lang.StringBuilder r0 = r0.append(r1)     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            java.lang.String r0 = r0.toString()     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            com.tdqy.cadre.modular.profess.utils.TextUtil.readStr = r0     // Catch: FileNotFoundException -> 0x004b, IOException -> 0x0043
            goto L_0x0016
        L_0x0040:
            goto L_0x0048
        L_0x0043:
            r6 = move-exception
            r0 = r6
            r0.printStackTrace()     // Catch: FileNotFoundException -> 0x004b
        L_0x0048:
            goto L_0x0050
        L_0x004b:
            r6 = move-exception
            r0 = r6
            r0.printStackTrace()
        L_0x0050:
            java.io.PrintStream r0 = java.lang.System.out
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r2 = r1
            r2.<init>()
            java.lang.String r2 = "文件内容是:\r\n"
            java.lang.StringBuilder r1 = r1.append(r2)
            java.lang.String r2 = com.tdqy.cadre.modular.profess.utils.TextUtil.readStr
            java.lang.StringBuilder r1 = r1.append(r2)
            java.lang.String r1 = r1.toString()
            r0.println(r1)
            java.lang.String r0 = com.tdqy.cadre.modular.profess.utils.TextUtil.readStr
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: com.tdqy.cadre.modular.profess.utils.TextUtil.readTxtFile():java.lang.String");
    }

    public static void writeTxtFile(String newStr) throws IOException {
        String filein = newStr + "\r\n" + readStr + "\r\n";
        RandomAccessFile mm = null;
        try {
            try {
                mm = new RandomAccessFile(filename, "rw");
                mm.writeBytes(filein);
                if (mm != null) {
                    try {
                        mm.close();
                    } catch (IOException e2) {
                        e2.printStackTrace();
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
                if (mm != null) {
                    try {
                        mm.close();
                    } catch (IOException e22) {
                        e22.printStackTrace();
                    }
                }
            }
        } catch (Throwable th) {
            if (mm != null) {
                try {
                    mm.close();
                } catch (IOException e23) {
                    e23.printStackTrace();
                }
            }
            throw th;
        }
    }

    public static void replaceTxtByStr(String oldStr, String replaceStr) {
        try {
            File file = new File(path);
            BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            StringBuffer buf = new StringBuffer();
            int j = 1;
            while (true) {
                String temp = br.readLine();
                if (temp == null || temp.equals(oldStr)) {
                    break;
                }
                buf = buf.append(temp).append(System.getProperty("line.separator"));
                j++;
            }
            StringBuffer buf2 = buf.append(replaceStr);
            while (true) {
                String temp2 = br.readLine();
                if (temp2 != null) {
                    buf2 = buf2.append(System.getProperty("line.separator")).append(temp2);
                } else {
                    br.close();
                    PrintWriter pw = new PrintWriter(new FileOutputStream(file));
                    pw.write(buf2.toString().toCharArray());
                    pw.flush();
                    pw.close();
                    return;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getPath() {
        return path;
    }

    public static void setPath(String path2) {
        path = path2;
    }

    public static File getFilename() {
        return filename;
    }

    public static void setFilename(File filename2) {
        filename = filename2;
    }
}
